from django.apps import AppConfig
from django.conf import settings

class CmdbConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'cmdb'

    def ready(self):
        print('cmdb的ready~~~~~~~~~@@@@@@')  # 应用初始化的时候执行一次
        # cmdb连接
        from mongoengine.connection import _connections, _connection_settings
        from mongoengine import connect  # Pymongo MongoClient
        print(_connections, _connection_settings)
        connect(**settings.MONGODB_DATABASES)  # db或name，alias缺省是default, host\port\tz_aware\username\password
        # 连接后，会把连接对象防在固定的地方，ODM来用，就去里面拿
        # _connections 字典，连接们；_connection_settings 连接的配置们
        print(_connections, _connection_settings)